#include <stdio.h>

#define SIZE        24
#define ELEAM    128

struct stu_staff {
    char name[SIZE];
    float chinese;
    float math;
    float english;
    float language;
    float max;
    int flags;
};

struct stu_staff *staff = NULL;

static void init_staff( void )
{
    staff = ( struct stu_staff * )malloc( sizeof( struct stu_staff ) * ELEAM );

    memset( staff, 0, sizeof( struct stu_staff ) * ELEAM );

    return ;
}

static int stu_add( void )
{
    struct stu_staff *stu = staff;
    int idx = 0;

    for ( idx = 0; idx < ELEAM; idx++ ) {
        if ( stu[idx].flags == 0 ) {
            printf( "Pls enter student name:" );
            scanf( "%s", stu[idx].name);

          //  printf( "\n\n" );

            //printf( "number:" );
            //printf( "%f", &ddd );
            
            printf( "Chinese point:" );
            scanf( "%f", &stu[idx].chinese );

            printf( "Math point:" );
            scanf( "%f", &stu[idx].math );

            printf( "English point:" );
            scanf( "%f", &stu[idx].english );

            stu[idx].flags = 1;

            break;
        } 
    }

    return 1;
}

static int stu_del( const char *name )
{
    return 1;
}


static void stu_search( const char *name )
{
    struct stu_staff *stu = staff;
    int idx = 0;

    for ( idx = 0; idx < ELEAM; idx++ ) {
        if ( strcmp( name, stu[idx].name ) == 0) {
            printf( "%s : \n", name );
            printf( "Chinese: %2f\n", stu[idx].chinese );
            printf( "Math: %2f\n", stu[idx].math );
            printf( "English: %2f", stu[idx].english );
            printf( "\n\n" );
            break;
        }
    }

    return ;
}

int main( void )
{
    struct stu_staff *stu = staff;
    char oper[16];
    char name[SIZE];
    
    int idx = 0;

    init_staff();

    printf( "Entering pls type <add>\n" );
    printf( "Search pls type  <search>\n" );
    printf( "Delete pls type   <del>\n" );
    printf( "Quit pls type      <quit>\n" );


    while ( 1 ) {

        printf( "Pls enter operate:" );
        scanf( "%s", &oper );

        if ( strcmp( oper, "add" ) == 0 ) {
            stu_add();
            continue;
        }
        else if ( strcmp( oper, "del" ) == 0 ) {
            printf( "Pls input student name for delete:" );
            scanf( "%s", &name );
            stu_del( name );
            continue;
        } else if ( strcmp( oper, "search" )  == 0 ) {
            printf( "Pls input student name for search:" );
            scanf( "%s", &name );
            stu_search( name );
            continue;
        } else if ( strcmp( oper, "quit" ) == 0 )  {
            break;        
        }else {
            printf( "Enter oper error pls reenter.\n" );
            continue;
        }
             
    }

    return 1;
}

